package com.xuetang9.t9.xinhuaxia.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.xuetang9.t9.xinhuaxia.beans.FirstCategory;
import com.xuetang9.t9.xinhuaxia.beans.Goods;
import com.xuetang9.t9.xinhuaxia.beans.GoodsPicturepath;
import com.xuetang9.t9.xinhuaxia.mappers.GoodsPicturepathMapper;
import com.xuetang9.t9.xinhuaxia.service.IGoodsPicturepathService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @author 李亚奇
 * @version 1.0
 * @desc TODO
 * @date 2020/3/3 14:01
 * @copyright liyq
 * @address 成都西部国际金融中心2栋2201
 **/
@Service
@Resource(name = "goodsPicturepathMapper")
public class GoodsPicturepathService implements IGoodsPicturepathService {
    @Autowired
    private GoodsPicturepathMapper goodsPicturepathMapper;
    @Override
    public boolean insert(GoodsPicturepath goodsPicturepath) {
        return goodsPicturepathMapper.insertSelective(goodsPicturepath)>0;
    }

    @Override
    public boolean remove(Long id) {
        return goodsPicturepathMapper.deleteByPrimaryKey(id)>0;
    }

    @Override
    public boolean update(GoodsPicturepath goodsPicturepath) {
        return goodsPicturepathMapper.updateByPrimaryKeySelective(goodsPicturepath)>0;
    }

    @Override
    public GoodsPicturepath queryById(Long id) {
        return goodsPicturepathMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<GoodsPicturepath> queryByGoodsId(Long id) {
        GoodsPicturepath goodsPicturepath = new GoodsPicturepath();
        goodsPicturepath.setGpGoodsid(id);
        return goodsPicturepathMapper.select(goodsPicturepath);
    }

    @Override
    public PageInfo<GoodsPicturepath> queryByPage(int currentPage, int perPageSize) {
        PageHelper.startPage(currentPage,perPageSize);
        PageHelper.orderBy("gp_id desc");
        List<GoodsPicturepath> goodsPicturepaths = goodsPicturepathMapper.selectAll();
        PageInfo<GoodsPicturepath> pageInfo = new PageInfo<>(goodsPicturepaths);
        return pageInfo;
    }
}
